package com.yj.cmp.sdk.fusioncompute.network.dvswitch;

import com.yj.cmp.sdk.fusioncompute.common.utils.RequestUtils;
import com.yj.cmp.sdk.fusioncompute.network.dvswitch.vo.DVSwitchDetailVo;
import com.yj.cmp.sdk.fusioncompute.network.dvswitch.vo.DVSwitchListVo;
import org.springframework.stereotype.Component;
import retrofit2.Response;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Harvey_Yang
 * @date 2021/8/28 11:15
 */
@Component
public class FcSwitchApi {
    FcSwitchService fcSwitchService;

    public FcSwitchApi(FcSwitchService fcSwitchService) {
        this.fcSwitchService = fcSwitchService;
    }

    /**
     * 分布式交换机列表
     *
     * @param headerMap
     * @return
     * @throws Exception
     */
    public List<DVSwitchListVo.DvSwitchsDTO> DVSwitchList(Map<String, Object> headerMap) throws Exception {
        Response<DVSwitchListVo> response = fcSwitchService.DVSwitchList(headerMap).execute();
        RequestUtils.isSuccessful(response);
        if (null != response.body()) {
            return response.body().getDvSwitchs();
        }
        return new ArrayList<>(0);
    }

    /**
     * 分布式交换机详情
     *
     * @param headerMap
     * @param dvswitchId
     * @return
     * @throws Exception
     */
    public DVSwitchDetailVo DVSwitchDetails(Map<String, Object> headerMap, String dvswitchId) throws Exception {
        Response<DVSwitchDetailVo> response = fcSwitchService.DVSwitchDetails(headerMap, dvswitchId).execute();
        RequestUtils.isSuccessful(response);
        if (null != response.body()) {
            return response.body();
        }
        return new DVSwitchDetailVo();
    }
}
